<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return['ischecklogin']=$this->model('member')->checklogin();
$credit_types=credit_types(true);
if($_RQ['op']=='get'){
	$up_type=$tixianset['up_type']?:3;
	if($_SESSION['onemerchid']){
		$member=model('jy_merch/member')->getdetail($_SESSION['onemerchid'],$_SESSION['uid']);
	}else{
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	}
	$tinum=intval($return['allmoney']/$tixianset['man_fee']);
	$return['man_fee']=$tixianset['man_fee'];
	$return['member']=$member;
	$return['params']['type']=$_RQ['type']?:3;
	$return['allmoney']=$member['credit'.$return['params']['type']];
	$return['typetitle']=$credit_types[$return['params']['type']];
	if($return['params']['type']==3){
		$tips='购买商品，参与分享都可以获得《'.$return['typetitle'].'》哦！';
	}elseif($return['params']['type']==4){
		$tips='可以充值获得《'.$return['typetitle'].'》哦！';
	}if($return['params']['type']==6){
		$tips='签到，直推人参与拼团，购买指定商品，都可以获得《'.$return['typetitle'].'》哦！';
	}
	$return['tips']=$tips;
	$return['is_open']=$tixianset['is_open'];
	$return['open_upbaofee']=$tixianset['open_upbaofee'];
	$return['balance_open']=$this->setting['balance_open'];
	$return['balance_per']=$this->setting['balance_per']?:0;
	$return['balance_tobi']=$this->setting['balance_tobi']?:50;
	$return['balance_tofee']=$this->setting['balance_tofee']?:50;
	$return['balance_hour']=$this->setting['balance_hour'];
	$return['post']=array('type'=>$return['params']['type']);
	set_html('title','我的'.$return['typetitle']);
	exi($return);
}
if($_RQ['op']=='fenlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
	}
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('core_credit_log',$params,array($pindex,$psize),$total,array('id','type','is_add','fee','remark','createtime'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			$item['typetitle']=$credit_types[$item['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='congzhi'){
	$post=get_postdata();
	$type=$post['type'];
	if(!$type){
		exi('请选择要转账的种类！','erroe');
	}
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	if(!$post['fee']){
		exi('请输入转账'.$this->db_title.'！','erroe');
	}
	if(!$post['mobile']){
		exi('请输入收款人账户/手机号！','erroe');
	}
	if($member['credit'.$type]<$post['fee']){
		exi('转账额度不能大于，当前积分额度！','erroe');
	}
	$tomember=pdo_get('core_members',array('username'=>$post['mobile']));
	$tomid=$tomember['id'];
	if(!$tomid){
		$tomember=pdo_get('core_members',array('mobile'=>$post['mobile']));
		$tomid=$tomember['onemid']?:$tomember['id'];
	}
	if(!$tomid){
		exi('没找到收款人，转账失败！','erroe');
	}
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$type,$post['fee'],false,'jy_liangoods','转账给:'.$post['mobile']);
	model('core/member')->member_credit($tomid,'credit'.$type,$post['fee'],true,'jy_liangoods',$member['username'].'的转账');
	exi('转账成功！');
}
if($_RQ['op']=='tixian'){
	$balance_per=$this->setting['balance_per']?:0;
	$balance_tobi=$this->setting['balance_tobi']?:50;
	$balance_tofee=$this->setting['balance_tofee']?:50;
	if($this->setting['balance_open']){
		exi('当前不支持茶币提现操作！','erroe');
	}
	$balance_hour=$this->setting['balance_hour'];
	$day=date('Y/m/d');
	$start=strtotime($day.' '.$balance_hour['start']);
	$end=strtotime($day.' '.$balance_hour['end']);
	if($balance_hour && ($start>time() || time()>$end)){
		exi('当前时间段不支持提现！','erroe');
	}
	$post=get_postdata();
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	if(!$post['fee']){
		exi('请输入转账'.$this->db_title.'！额度','erroe');
	}
	$balance_perfee=$balance_per*$post['fee']/100;
	$allfee=$balance_perfee+$post['fee'];
	if($member['credit3']<$allfee){
		$maxfee=$member['credit3']-$balance_perfee;
		exi('转账额度不能大于'.$maxfee.'(需扣手续费'.$balance_perfee.')!','erroe');
	}
	$credit2=$balance_tofee*$post['fee']/100;
	$credit6=$balance_tobi*$post['fee']/100;
	model('core/member')->member_credit($_SESSION['uid'],'credit3',$allfee,false,'jy_liangoods','提现扣除');
	model('core/member')->member_credit($_SESSION['uid'],'credit2',$credit2,true,'jy_liangoods','茶币的提现');
	model('core/member')->member_credit($_SESSION['uid'],'credit6',$credit6,true,'jy_liangoods','茶币的提现');
	exi('操作成功！');
}